package com.example.administrator.xposedtest2;

/**
 * Created by Administrator on 2018/2/9.
 */

import android.util.Log;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

public class Tutorial implements IXposedHookLoadPackage {
    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {

        // 将包名不是 com.kali.login 的应用剔除掉
        if (!lpparam.packageName.equals("com.example.administrator.xposedtest2"))
            return;
        //XposedBridge.log("Loaded app: " + lpparam.packageName);

        // Hook isOk 方法
        findAndHookMethod("com.example.administrator.xposedtest2.MainActivity", lpparam.classLoader, "isOK", String.class,
                String.class, new XC_MethodHook() {

                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//                        XposedBridge.log("---Hook Start---");
//                        XposedBridge.log("Uname = " + param.args[0]);
//                        XposedBridge.log("Passwd = " + param.args[1]);
                        param.args[0]="admin";
                        param.args[1]="admin";
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        XposedBridge.log("---Hook End---");
//                        XposedBridge.log("Uname = " + param.args[0]);
//                        XposedBridge.log("Passwd = " + param.args[1]);
                        XposedBridge.log("param is changed already" );

                    }
                });
    }
}
